var config = require('../../../utils/config.js');
var netutil = require('../../../utils/netutil.js');
var baseutil = require('../../../utils/baseutil.js');
let { WeToast } = require('../../../src/wetoast.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    TUserInfo:null,
    passengerList:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      TUserInfo: app.globalData.TUserInfo
    })
    //创建可重复使用的toast实例，并附加到this上，通过this.wetoast访问
    new app.WeToast()

    this.getPassengerList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  getPassengerList:function(){
    var THIS = this
    var url = config.getBaseUrl("CommonApi", "QueryFrequentPassenger");
    var Data = new Object();
    Data.SiteId = this.data.TUserInfo.SiteID
    Data.EID = this.data.TUserInfo.EID
    Data.UserID = this.data.TUserInfo.UserID
    Data.Name = ""

    baseutil.log(url);
    netutil.post(
      url, Data,
      function (res) {
        baseutil.log(res.data);
        if (res.data.ResponseMetaInfo.StatusCode == '0') {
          var passengerList = res.data.Data.DataPassenger;
          if (passengerList == null || passengerList.length == 0) {
            THIS.setData({ passengerList: null })
          } else {
            THIS.setData({ passengerList: passengerList })
          }

        } else {
          THIS.wetoast.toast({
            title: res.data.ResponseMetaInfo.Reason,
            duration: 1000
          })
        }
      },
      function (res) {

      })
  },
  passengerAdd:function(){
    baseutil.openNewPage('../../passenger/passengerAdd/passengerAdd?type=' + 1 + "&isFrom=" + '1');
  },
  
  editPassenger:function(e){
   var position= parseInt(e.currentTarget.dataset.position)
   app.globalData.tempData = this.data.passengerList[position]
   baseutil.openNewPage('../../passenger/passengerAdd/passengerAdd?type=' + 0 + "&isFrom=" + '1') ;
  }
})